<template>
  <!-- 放置一个图标 -->
  <div>
    <!-- 方式1：直接更换类名 -->
    <svg-icon
      :icon-class="ison ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="handleToggle"
    />
    <!-- 方式2：准备2套结构 -->
    <!-- <svg-icon
      v-if="isOn"
      class="exit-fullscreen"
      @click="handleToggle"
    />
    <svg-icon
      v-else
      class="fullscreen"
      @click="handleToggle"
    /> -->
  </div>
</template>

<script>
import screenFull from "screenfull";
export default {
  name: "ScreenFull",
  data() {
    return {
      //默认不显示
      ison: false,
    };
  },
  methods: {
    handleToggle() {
      if (screenFull.isEnabled) {
        //如果浏览器支持全屏
        screenFull.toggle(); // 调用toggle()方法进行切换
        this.ison = !this.ison; // 开关取反
      } else {
        this.$message.warning("请升级浏览器");
      }
    },
  },
};
</script>
<style scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  fill: #fff;
  cursor: pointer;
}
</style>
